const { cleanDatEnglishText } = require("../src/utils/datTextCleaner");

// 测试用例
const testCases = [
  {
    input: '"$you words$$$$$"',
    expected: '"',
    description: "以$开头，包含空格的格式",
  },
  {
    input: "^products$product$$$$$",
    expected: "^products",
    description: "标准word$word格式",
  },
  {
    input: "due to$due to$$$$$",
    expected: "due to",
    description: "多词词组格式",
  },
  {
    input: "as soon as possible$as soon as possible$$$$$",
    expected: "as soon as possible",
    description: "长词组格式",
  },
  {
    input: "^Please$please$$$$$^ ^give$give$$$$$^ ^our$our$$$$$^",
    expected: "^Please ^give ^our ^",
    description: "多个格式组合",
  },
];

console.log("测试新的处理逻辑:\n");

testCases.forEach((testCase, index) => {
  const result = cleanDatEnglishText(testCase.input);
  const passed = result === testCase.expected;

  console.log(`测试 ${index + 1} (${testCase.description}):`);
  console.log(`  输入: ${testCase.input}`);
  console.log(`  期望: ${testCase.expected}`);
  console.log(`  实际: ${result}`);
  console.log(`  结果: ${passed ? "通过" : "失败"}`);
  console.log("");
});

// 特别测试"$you words$$$$$"格式
console.log('特别测试"$you words$$$$$"格式:');
const specialCase = '"$you words$$$$$"';
const specialResult = cleanDatEnglishText(specialCase);

console.log(`输入: ${specialCase}`);
console.log(`输出: ${specialResult}`);
console.log("详细处理步骤:");

// 演示处理步骤
console.log(`  1. 原始文本: "${specialCase}"`);
const step1 = specialCase.replace(/\$[^$]*\${4,}/g, "");
console.log(`  2. 去掉$和$$$$之间的内容: "${step1}"`);
const step2 = step1.replace(/\^/g, " ").replace(/\$/g, " ").replace(/◆/g, "");
console.log(`  3. 处理特殊符号: "${step2}"`);
const step3 = step2.split(" ").filter(word => word.trim() !== "");
console.log(`  4. 分割单词: [${step3.map(w => `"${w}"`).join(", ")}]`);
const finalResult = step3.join(" ").trim();
console.log(`  5. 最终结果: "${finalResult}"`);
